package com.bdqn.springweb.controller;

import com.bdqn.springweb.pojo.User;
import com.bdqn.springweb.service.Userservice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
    @Resource
    private Userservice UserService;


    /**
     * 查询所有用户数据
     * @return
     */
    @GetMapping("/users")
    public List<User> findAllUsers(){
        List<User> Users = UserService.findAllUsers();
        return Users;
    }

    /**
     * 根据用户id查询对应的用户信息
     * @return
     */
    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Long usrId){
        User User = UserService.getUser(usrId);
        return User;
    }

    /**
     * 新增用户
     */
    @PostMapping("/user")
    public void addUser(User User){
        UserService.addUser(User);
    }

    /**
     * 修改用户
     */
    @PutMapping("/user")
    public void updateUser(User User){
        UserService.updateUser(User);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId){
        UserService.deleteUser(usrId);
    }
}

